﻿Imports System.ComponentModel

''' <summary>
''' Représente une variable (colonne d'une table ou d'une requête) dans la base de données
''' </summary>
''' <remarks></remarks>
<Serializable()> Public Class ChampsBDD
    Inherits PTIC_Util.BaseNotifyPropertyChangeComponentModel

#Region "Variables de classe"

    'Nom du champs
    Protected _nom As String
    'Format du champs (stockage + affichage)
    Protected _format As FormatChamps

    'Valeurs idstinctes
    <NonSerialized()> Protected _valeursDistinctes As DataTable

#End Region

#Region "Constructeurs"
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New(ByVal nom As String, ByVal format As FormatChamps)
        _nom = nom
        _format = format
        _valeursDistinctes = Nothing
    End Sub
#End Region

#Region "Propriétés"
    ''' <summary>
    ''' Nom du champs
    ''' </summary>
    Public Property Nom() As String
        Get
            Return _nom
        End Get
        Set(ByVal value As String)
            OnPropertyChanging("Nom")
            _nom = value
            OnPropertyChanged("Nom")
        End Set
    End Property

    ''' <summary>
    ''' Format du champs
    ''' </summary>
    ''' <remarks></remarks>
    Public Property Format() As FormatChamps
        Get
            Return _format
        End Get
        Set(ByVal value As FormatChamps)
            OnPropertyChanging("Format")
            _format = value
            OnPropertyChanged("Format")
        End Set
    End Property

    ''' <summary>
    ''' Valeurs distinctes prises par le champs
    ''' </summary>
    Public Property valeursDistinctes() As DataTable
        Set(ByVal value As DataTable)
            OnPropertyChanging("valeursDistinctes")
            _valeursDistinctes = value
            OnPropertyChanged("valeursDistinctes")
            OnPropertyChanged("NbValeursDistinctes")
        End Set
        Get
            Return _valeursDistinctes
        End Get
    End Property

    Public ReadOnly Property NbValeursDistinctes() As Integer
        Get
            If _valeursDistinctes Is Nothing Then Return 0 Else Return _valeursDistinctes.Rows.Count
        End Get
    End Property


#End Region

#Region "Méthodes de manipulation de l'objet"
    ''' <summary>
    ''' Renvoie une copie du champs
    ''' </summary>
    Public Function copy() As ChampsBDD
        Return New ChampsBDD(_nom, _format.copy())
    End Function
#End Region

End Class
